<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/private-blog/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/private-blog/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/private-blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/private-blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/private-blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/private-blog/images/yy.jpg?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/private-blog/images/icon/yy32.jpg?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/private-blog/images/icon/yy16.jpg?v=5.1.4">


  <link rel="mask-icon" href="/private-blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Devops - SpringBoot - Jenkins," />










<meta name="description" content="构建背景：因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。">
<meta name="keywords" content="Devops - SpringBoot - Jenkins">
<meta property="og:type" content="article">
<meta property="og:title" content="Jenkins-码云-Springboot自动构建">
<meta property="og:url" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;2020&#x2F;07&#x2F;10&#x2F;Jenkins-%E7%A0%81%E4%BA%91-Springboot%E8%87%AA%E5%8A%A8%E6%9E%84%E5%BB%BA&#x2F;index.html">
<meta property="og:site_name" content="Culaccino&#39;s blog">
<meta property="og:description" content="构建背景：因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;4.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;5.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;6.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;7.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;8.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;9.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;11.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;10.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;13.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;12.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;14.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;15.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;16.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;17.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;18.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;19.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;20.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;21.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;22.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;23.png">
<meta property="og:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;24.png">
<meta property="og:updated_time" content="2021-09-30T03:32:24.399Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http:&#x2F;&#x2F;zy0912.gitee.io&#x2F;private-blog&#x2F;images&#x2F;%E8%BF%90%E7%BB%B4&#x2F;4.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/private-blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://zy0912.gitee.io/private-blog/2020/07/10/Jenkins-码云-Springboot自动构建/"/>





  <title>Jenkins-码云-Springboot自动构建 | Culaccino's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/private-blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Culaccino's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Nothing is impossible！！</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/private-blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/private-blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/private-blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/private-blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://zy0912.gitee.io/private-blog/private-blog/2020/07/10/Jenkins-%E7%A0%81%E4%BA%91-Springboot%E8%87%AA%E5%8A%A8%E6%9E%84%E5%BB%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Culaccino">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/private-blog/images/yy.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Culaccino's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Jenkins-码云-Springboot自动构建</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-07-10T10:41:11+08:00">
                2020-07-10
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/private-blog/categories/%E8%BF%90%E7%BB%B4/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/private-blog/categories/%E8%BF%90%E7%BB%B4/Jenkins/" itemprop="url" rel="index">
                    <span itemprop="name">Jenkins</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本页总阅读数<i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="构建背景："><a href="#构建背景：" class="headerlink" title="构建背景："></a>构建背景：</h2><h4 id="因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。"><a href="#因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。" class="headerlink" title="因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。"></a>因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。</h4><a id="more"></a>
<h2 id="环境准备："><a href="#环境准备：" class="headerlink" title="环境准备："></a>环境准备：</h2><blockquote>
<p>JDK<br>Maven<br>Git<br>码云springboot代码仓库</p>
</blockquote>
<h4 id="emsp-emsp-环境变量-路径以自己本机为主-："><a href="#emsp-emsp-环境变量-路径以自己本机为主-：" class="headerlink" title="&emsp;&emsp;环境变量(路径以自己本机为主)："></a>&emsp;&emsp;环境变量(路径以自己本机为主)：</h4><figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">export JAVA_HOME=/usr/lib/jvm/java-<span class="number">1.8</span>.<span class="number">0</span>-openjdk-<span class="number">1.8</span>.<span class="number">0.252</span>.b09-<span class="number">2</span>.el7_8.x86_64</span><br><span class="line">export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar</span><br><span class="line">export PATH=$PATH:$JAVA_HOME/bin</span><br><span class="line"></span><br><span class="line">export PATH=/usr/local/git/bin:$PATH</span><br><span class="line"></span><br><span class="line">MAVEN_HOME=/usr/local/maven/apache-maven-<span class="number">3.6</span>.<span class="number">1</span></span><br><span class="line">export MAVEN_HOME</span><br><span class="line">export PATH=$&#123;PATH&#125;:$&#123;MAVEN_HOME&#125;/bin</span><br></pre></td></tr></table></figure>

<h2 id="1-安装Jenkins"><a href="#1-安装Jenkins" class="headerlink" title="1.安装Jenkins"></a>1.安装Jenkins</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># yum源</span></span><br><span class="line">sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo</span><br><span class="line"></span><br><span class="line"><span class="comment"># 公钥</span></span><br><span class="line">sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装</span></span><br><span class="line">yum install jenkins</span><br></pre></td></tr></table></figure>
<h4 id="emsp-emsp-这里设置一下用户，端口-默认8080-有需要也可更换"><a href="#emsp-emsp-这里设置一下用户，端口-默认8080-有需要也可更换" class="headerlink" title="&emsp;&emsp;这里设置一下用户，端口(默认8080)有需要也可更换"></a>&emsp;&emsp;这里设置一下用户，端口(默认8080)有需要也可更换</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/sysconfig/jenkins</span><br></pre></td></tr></table></figure>
<blockquote>
<p>JENKINS_USER=”root”<br>JENKINS_PORT=”8088”</p>
</blockquote>
<h4 id="emsp-emsp-启动："><a href="#emsp-emsp-启动：" class="headerlink" title="&emsp;&emsp;启动："></a>&emsp;&emsp;启动：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo service jenkins restart</span><br></pre></td></tr></table></figure>
<h4 id="emsp-emsp-第一次进入会让你填写密钥（根据提示查看）"><a href="#emsp-emsp-第一次进入会让你填写密钥（根据提示查看）" class="headerlink" title="&emsp;&emsp;第一次进入会让你填写密钥（根据提示查看）"></a>&emsp;&emsp;第一次进入会让你填写密钥（根据提示查看）</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /var/lib/jenkins/secrets/initialAdminPassword</span><br></pre></td></tr></table></figure>
<p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/4.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-完成后，需要插件安装，选择默认"><a href="#emsp-emsp-完成后，需要插件安装，选择默认" class="headerlink" title="&emsp;&emsp;完成后，需要插件安装，选择默认"></a>&emsp;&emsp;完成后，需要插件安装，选择默认</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/5.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-创建你的Jenkins用户"><a href="#emsp-emsp-创建你的Jenkins用户" class="headerlink" title="&emsp;&emsp;创建你的Jenkins用户"></a>&emsp;&emsp;创建你的Jenkins用户</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/6.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-到这里就已经基本安装完成，登录进入到配置页面"><a href="#emsp-emsp-到这里就已经基本安装完成，登录进入到配置页面" class="headerlink" title="&emsp;&emsp;到这里就已经基本安装完成，登录进入到配置页面"></a>&emsp;&emsp;到这里就已经基本安装完成，登录进入到配置页面</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/7.png" alt="Yoyou"><br><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/8.png" alt="Yoyou"></p>
<h2 id="2-下载插件："><a href="#2-下载插件：" class="headerlink" title="2.下载插件："></a>2.下载插件：</h2><h4 id="系统管理-gt-插件管理-gt-可选插件"><a href="#系统管理-gt-插件管理-gt-可选插件" class="headerlink" title="系统管理-&gt;插件管理-&gt;可选插件"></a>系统管理-&gt;插件管理-&gt;可选插件</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/9.png" alt="Yoyou"></p>
<blockquote>
<p>Gitee Plugin</p>
<p>Maven Integration plugin</p>
<p>Pipeline Maven Integration Plugin</p>
</blockquote>
<h2 id="3-全局配置："><a href="#3-全局配置：" class="headerlink" title="3.全局配置："></a>3.全局配置：</h2><h4 id="系统管理-gt-全局工具配置"><a href="#系统管理-gt-全局工具配置" class="headerlink" title="系统管理-&gt;全局工具配置"></a>系统管理-&gt;全局工具配置</h4><h4 id="emsp-emsp-1）JDK配置："><a href="#emsp-emsp-1）JDK配置：" class="headerlink" title="&emsp;&emsp;1）JDK配置："></a>&emsp;&emsp;1）JDK配置：</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/11.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-2）Git配置："><a href="#emsp-emsp-2）Git配置：" class="headerlink" title="&emsp;&emsp;2）Git配置："></a>&emsp;&emsp;2）Git配置：</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/10.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-3）Maven配置："><a href="#emsp-emsp-3）Maven配置：" class="headerlink" title="&emsp;&emsp;3）Maven配置："></a>&emsp;&emsp;3）Maven配置：</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/13.png" alt="Yoyou"><br><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/12.png" alt="Yoyou"></p>
<h2 id="4-新建任务："><a href="#4-新建任务：" class="headerlink" title="4.新建任务："></a>4.新建任务：</h2><h5 id="emsp-emsp-1）构建一个自由风格的软件项目"><a href="#emsp-emsp-1）构建一个自由风格的软件项目" class="headerlink" title="&emsp;&emsp;1）构建一个自由风格的软件项目"></a>&emsp;&emsp;1）构建一个自由风格的软件项目</h5><h5 id="emsp-emsp-2）General参数配置："><a href="#emsp-emsp-2）General参数配置：" class="headerlink" title="&emsp;&emsp;2）General参数配置："></a>&emsp;&emsp;2）General参数配置：</h5><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/14.png" alt="Yoyou"><br><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/15.png" alt="Yoyou"><br><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/16.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-3）源码管理："><a href="#emsp-emsp-3）源码管理：" class="headerlink" title="&emsp;&emsp;3）源码管理："></a>&emsp;&emsp;3）源码管理：</h4><h4 id="emsp-emsp-emsp-emsp-设置码云仓库连接，以及指定分支"><a href="#emsp-emsp-emsp-emsp-设置码云仓库连接，以及指定分支" class="headerlink" title="&emsp;&emsp;&emsp;&emsp;设置码云仓库连接，以及指定分支"></a>&emsp;&emsp;&emsp;&emsp;设置码云仓库连接，以及指定分支</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/17.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-emsp-emsp-构建触发器（重点，事关码云推送能否触发构建）："><a href="#emsp-emsp-emsp-emsp-构建触发器（重点，事关码云推送能否触发构建）：" class="headerlink" title="&emsp;&emsp;&emsp;&emsp;构建触发器（重点，事关码云推送能否触发构建）："></a>&emsp;&emsp;&emsp;&emsp;构建触发器（重点，事关码云推送能否触发构建）：</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/18.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-emsp-emsp-将链接复制到码云的webhooks上，生成密码同样复制到码云"><a href="#emsp-emsp-emsp-emsp-将链接复制到码云的webhooks上，生成密码同样复制到码云" class="headerlink" title="&emsp;&emsp;&emsp;&emsp;将链接复制到码云的webhooks上，生成密码同样复制到码云"></a>&emsp;&emsp;&emsp;&emsp;将链接复制到码云的webhooks上，生成密码同样复制到码云</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/19.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-4）构建（执行shell）："><a href="#emsp-emsp-4）构建（执行shell）：" class="headerlink" title="&emsp;&emsp;4）构建（执行shell）："></a>&emsp;&emsp;4）构建（执行shell）：</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/20.png" alt="Yoyou"></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/bin/bash -il</span></span><br><span class="line">mvn clean install -Dmaven.test.skip=<span class="literal">true</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$jar_path</span> <span class="variable">$jar_name</span></span><br><span class="line"><span class="built_in">cd</span> /root/shell/</span><br><span class="line">./stop.sh <span class="variable">$jar_name</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"Execute shell Finish"</span></span><br><span class="line">./start.sh <span class="variable">$jar_path</span> <span class="variable">$jar_name</span> <span class="variable">$project_name</span></span><br></pre></td></tr></table></figure>
<h4 id="emsp-emsp-emsp-emsp-启动脚本："><a href="#emsp-emsp-emsp-emsp-启动脚本：" class="headerlink" title="&emsp;&emsp;&emsp;&emsp;启动脚本："></a>&emsp;&emsp;&emsp;&emsp;启动脚本：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">jar_path=<span class="variable">$&#123;1&#125;</span></span><br><span class="line">jar_name=<span class="variable">$&#123;2&#125;</span></span><br><span class="line">project_name=<span class="variable">$&#123;3&#125;</span></span><br><span class="line"><span class="built_in">cd</span> <span class="variable">$&#123;jar_path&#125;</span>/<span class="variable">$&#123;project_name&#125;</span>/target/</span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$&#123;jar_path&#125;</span>/<span class="variable">$&#123;project_name&#125;</span>/target/</span><br><span class="line"><span class="built_in">echo</span> nohup java -jar <span class="variable">$&#123;jar_name&#125;</span> &amp;</span><br><span class="line">BUILD_ID=dontKillMe nohup java -jar <span class="variable">$&#123;jar_name&#125;</span> &gt; /root/workspace/boot.log &amp;</span><br></pre></td></tr></table></figure>
<h4 id="emsp-emsp-emsp-emsp-停止脚本："><a href="#emsp-emsp-emsp-emsp-停止脚本：" class="headerlink" title="&emsp;&emsp;&emsp;&emsp;停止脚本："></a>&emsp;&emsp;&emsp;&emsp;停止脚本：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">jar_name=<span class="variable">$&#123;1&#125;</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"Stopping"</span> <span class="variable">$&#123;jar_name&#125;</span></span><br><span class="line">pid=`ps -ef | grep <span class="variable">$&#123;jar_name&#125;</span> | grep -v grep | awk <span class="string">'&#123;print $2&#125;'</span>`</span><br><span class="line"><span class="keyword">if</span> [ -n <span class="string">"<span class="variable">$pid</span>"</span> ]</span><br><span class="line"><span class="keyword">then</span></span><br><span class="line">   <span class="built_in">echo</span> <span class="string">"kill -9 的pid:"</span> <span class="variable">$pid</span></span><br><span class="line">   <span class="built_in">kill</span> -9 <span class="variable">$pid</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>

<h4 id="emsp-emsp-emsp-emsp-保存"><a href="#emsp-emsp-emsp-emsp-保存" class="headerlink" title="&emsp;&emsp;&emsp;&emsp;保存"></a>&emsp;&emsp;&emsp;&emsp;保存</h4><h2 id="5-开始构建："><a href="#5-开始构建：" class="headerlink" title="5.开始构建："></a>5.开始构建：</h2><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/21.png" alt="Yoyou"><br><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/22.png" alt="Yoyou"></p>
<h2 id="6-测试："><a href="#6-测试：" class="headerlink" title="6.测试："></a>6.测试：</h2><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/23.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-修改推送到码云仓库，刷新页面"><a href="#emsp-emsp-修改推送到码云仓库，刷新页面" class="headerlink" title="&emsp;&emsp;修改推送到码云仓库，刷新页面"></a>&emsp;&emsp;修改推送到码云仓库，刷新页面</h4><p><img src="/private-blog/images/%E8%BF%90%E7%BB%B4/24.png" alt="Yoyou"></p>
<h4 id="emsp-emsp-自动构建成功"><a href="#emsp-emsp-自动构建成功" class="headerlink" title="&emsp;&emsp;自动构建成功"></a>&emsp;&emsp;自动构建成功</h4>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>如果你觉得有帮助，慷慨如你，可以扫描下面的二维码赞赏一下</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/yy.jpg" alt="Culaccino 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/yy.jpg" alt="Culaccino 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/private-blog/tags/Devops-SpringBoot-Jenkins/" rel="tag"># Devops - SpringBoot - Jenkins</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/private-blog/2020/06/18/DockFile%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84/" rel="next" title="DockFile体系结构以及案例演示">
                <i class="fa fa-chevron-left"></i> DockFile体系结构以及案例演示
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/private-blog/2020/08/01/elk%E6%97%A5%E5%BF%97%E7%B3%BB%E7%BB%9F%E6%90%AD%E5%BB%BA/" rel="prev" title="elk日志系统搭建">
                elk日志系统搭建 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/private-blog/images/yy.jpg"
                alt="Culaccino" />
            
              <p class="site-author-name" itemprop="name">Culaccino</p>
              <p class="site-description motion-element" itemprop="description">A glass with a cold drink left a round watermark on the table.</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/private-blog/archives">
              
                  <span class="site-state-item-count">40</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/private-blog/categories/index.html">
                  <span class="site-state-item-count">32</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/private-blog/tags/index.html">
                  <span class="site-state-item-count">38</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zhengyue12" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://mail.qq.com/" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://info52.top" title="山有木兮" target="_blank">山有木兮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://dianzihut.com/" title="RE-Empire" target="_blank">RE-Empire</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#构建背景："><span class="nav-number">1.</span> <span class="nav-text">构建背景：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。"><span class="nav-number">1.0.1.</span> <span class="nav-text">因为前后端分离，后端项目每天至少部署5-6遍。起初想着一定要教会组内成员如何部署，以减轻自己的负担。后来也这么做了，亲自录了一个部署视频。当晚，小组内部群里发完录制视频，找学长唠嗑时提到这件事，抱怨了几句。学长一语惊醒梦中人，是啊，何不学一下Jenkins，实现自动化部署，一劳永逸。</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#环境准备："><span class="nav-number">2.</span> <span class="nav-text">环境准备：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-环境变量-路径以自己本机为主-："><span class="nav-number">2.0.1.</span> <span class="nav-text">  环境变量(路径以自己本机为主)：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-安装Jenkins"><span class="nav-number">3.</span> <span class="nav-text">1.安装Jenkins</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-这里设置一下用户，端口-默认8080-有需要也可更换"><span class="nav-number">3.0.1.</span> <span class="nav-text">  这里设置一下用户，端口(默认8080)有需要也可更换</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-启动："><span class="nav-number">3.0.2.</span> <span class="nav-text">  启动：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-第一次进入会让你填写密钥（根据提示查看）"><span class="nav-number">3.0.3.</span> <span class="nav-text">  第一次进入会让你填写密钥（根据提示查看）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-完成后，需要插件安装，选择默认"><span class="nav-number">3.0.4.</span> <span class="nav-text">  完成后，需要插件安装，选择默认</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-创建你的Jenkins用户"><span class="nav-number">3.0.5.</span> <span class="nav-text">  创建你的Jenkins用户</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-到这里就已经基本安装完成，登录进入到配置页面"><span class="nav-number">3.0.6.</span> <span class="nav-text">  到这里就已经基本安装完成，登录进入到配置页面</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-下载插件："><span class="nav-number">4.</span> <span class="nav-text">2.下载插件：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#系统管理-gt-插件管理-gt-可选插件"><span class="nav-number">4.0.1.</span> <span class="nav-text">系统管理-&gt;插件管理-&gt;可选插件</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-全局配置："><span class="nav-number">5.</span> <span class="nav-text">3.全局配置：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#系统管理-gt-全局工具配置"><span class="nav-number">5.0.1.</span> <span class="nav-text">系统管理-&gt;全局工具配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-1）JDK配置："><span class="nav-number">5.0.2.</span> <span class="nav-text">  1）JDK配置：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-2）Git配置："><span class="nav-number">5.0.3.</span> <span class="nav-text">  2）Git配置：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-3）Maven配置："><span class="nav-number">5.0.4.</span> <span class="nav-text">  3）Maven配置：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-新建任务："><span class="nav-number">6.</span> <span class="nav-text">4.新建任务：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#emsp-emsp-1）构建一个自由风格的软件项目"><span class="nav-number">6.0.0.1.</span> <span class="nav-text">  1）构建一个自由风格的软件项目</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#emsp-emsp-2）General参数配置："><span class="nav-number">6.0.0.2.</span> <span class="nav-text">  2）General参数配置：</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-3）源码管理："><span class="nav-number">6.0.1.</span> <span class="nav-text">  3）源码管理：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-emsp-emsp-设置码云仓库连接，以及指定分支"><span class="nav-number">6.0.2.</span> <span class="nav-text">    设置码云仓库连接，以及指定分支</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-emsp-emsp-构建触发器（重点，事关码云推送能否触发构建）："><span class="nav-number">6.0.3.</span> <span class="nav-text">    构建触发器（重点，事关码云推送能否触发构建）：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-emsp-emsp-将链接复制到码云的webhooks上，生成密码同样复制到码云"><span class="nav-number">6.0.4.</span> <span class="nav-text">    将链接复制到码云的webhooks上，生成密码同样复制到码云</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-4）构建（执行shell）："><span class="nav-number">6.0.5.</span> <span class="nav-text">  4）构建（执行shell）：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-emsp-emsp-启动脚本："><span class="nav-number">6.0.6.</span> <span class="nav-text">    启动脚本：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-emsp-emsp-停止脚本："><span class="nav-number">6.0.7.</span> <span class="nav-text">    停止脚本：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-emsp-emsp-保存"><span class="nav-number">6.0.8.</span> <span class="nav-text">    保存</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-开始构建："><span class="nav-number">7.</span> <span class="nav-text">5.开始构建：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-测试："><span class="nav-number">8.</span> <span class="nav-text">6.测试：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-修改推送到码云仓库，刷新页面"><span class="nav-number">8.0.1.</span> <span class="nav-text">  修改推送到码云仓库，刷新页面</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#emsp-emsp-自动构建成功"><span class="nav-number">8.0.2.</span> <span class="nav-text">  自动构建成功</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2019 &mdash; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Culaccino</span>

  
</div>

<!--
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>


-->

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js""></script>

  
    <span class="site-uv">
      本站访问数 <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      本站总访问量 <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  









  
  
    <script type="text/javascript" src="/private-blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/private-blog/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/private-blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/private-blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/private-blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/private-blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/private-blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/private-blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/private-blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/private-blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
